# coding=utf-8
"""
Created on 2018年08月29日
"""
from util_base.ufo_decorators import processor
from common_base.cmd import CMD
from processor_base.base_processor import BaseProcessor
from util_base.exception import ParamException, UFOException as E
from common_base.errors import AliveError
from setting_base.setting import C
import datetime


@processor(CMD.CMD_GET_UPLOAD_FEEDBACK_IMAGE_TOKEN, internal_access=True)
class GetUploadFeedbackImageToken(BaseProcessor):
    """
    GetUploadFeedbackImageToken
    """
    
    TAG = 'GetUploadFeedbackImageToken'
    
    def __init__(self, handler):
        """
        Constructor
        """
        BaseProcessor.__init__(self, handler)

    def process(self):
        """
        process protocol
        """
        userid = self.alive_cmsdb.get_userid_by_userkey(self.user_key)
        if not userid:
            raise E(AliveError.ERROR_USER_DOES_NOT_EXIST)

        datetime_obj = datetime.datetime.now()
        path = C('region_id') + '/' + C('storage')['path']['feedback'] + '/' + \
               str(datetime_obj.year) + '/' + str(datetime_obj.month) + '/'

        return dict(
            uploadUrl=C('storage')['upload']['url'],
            path=path,
            policy=C('storage')['upload']['feedback']['policy'],
            signature=C('storage')['upload']['feedback']['signature'],
            accessKey=C('storage')['upload']['feedback']['accessKey']
        )

    def _verify_params(self):
        """
        重写父类方法, 作参数校验
        """
